package com.example.messangersms;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class SmsMessaging extends Activity {
	private DatabaseConnection db;
	private int recipientId;
	private int senderId;
	private String message;
	private boolean messageSaved = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sms_messaging);
		db = new DatabaseConnection(this);
		
		//Grab extra data
		Bundle extraInfo = getIntent().getExtras();
		recipientId = Integer.parseInt(LoginActivity.UserId);
		senderId = extraInfo.getInt("SENDER_ID");
		message = extraInfo.getString("MESSAGE");
		
		//Grab the text views
		TextView senderIdText = (TextView) findViewById(R.id.senderIdText);
		TextView messageText = (TextView) findViewById(R.id.messageText);
		//Set the text views to the values passed in
		senderIdText.setText(""+senderId);
		messageText.setText(message);
		//senderIdText.setText("test");
		//messageText.setText("This is a longer test to see if it works!");
	}
	
	
	public void saveClick(View view){
		if(!messageSaved){
			//Insert the message on save click
			db.insertMessage(recipientId, senderId, message);
			Toast toast = Toast.makeText(getApplicationContext(), "Your message was saved!",
					Toast.LENGTH_LONG);
			toast.show();
			messageSaved = true;
		}else{
			Toast toast = Toast.makeText(getApplicationContext(), "Your message has already been saved before.",
					Toast.LENGTH_LONG);
			toast.show();
		}
		
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_sms_messaging, menu);
		return true;
	}

}
